def isPrime (x):
    if x==1:
        return False
    for i in range (2,x):
        if x%i==0:
            return False
    return True
ans=[]
n=int(input())
s=str(n)
if len(s)!=4:
    print("0")
a=str(n//1000)
b=str(n%1000//100)
c=str(n%100//10)
d=str(n%10)
y=[a,b,c,d,a+b,b+c,c+d,a+b+c,b+c+d,a+b+c+d]
print (y)
for x in y:
    if isPrime (int(x)):
        ans.append (int(x))
if len(ans)==0:
    print ("0")
else:
    print (max(ans))

